package com.seven.thread;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author sevenDay
 * @classname SevenTask
 * @description:
  demo :
    public void run() {
    LOGGER.info("taskId: {}  ,taskName: {} ",taskId,taskName);
    try {
    Thread.sleep(10000);
    } catch (InterruptedException e) {
    LOGGER.error("taskId: {}  ,taskName: {} 执行异常,异常信息 {}",taskId,taskName,e.getMessage());
    LOGGER.error("",e);
    }
    }
 * @date 2017/11/16
 */
@Data
public abstract class SevenRunnable implements Runnable,ThreadTask {

    private static final Logger LOGGER = LoggerFactory.getLogger(SevenRunnable.class);
    private int taskId;
    private String taskName;
    private long startTime;
    private long endTime;
    public SevenRunnable(String taskName,int taskId){
        this.taskName = taskName;
        this.taskId = taskId;
    }

    /**
     *用于实现线程执行的过程
     * @return
     * @throws Exception
     */
    @Override
    public abstract void run();

    /**
     * 设置线程的任务Id，可以是严格排序的Id
     * @param taskId
     */
    @Override
    public  void setTaskId(int taskId){this.taskId=taskId;};

    /**
     * 设置线程的任务名称
     * @param taskName
     */
    @Override
    public  void setTaskName(String taskName){this.taskName=taskName;};


    /**
     * 设置线程开始执行时间，用于统计线程执行效率
     * @param startTime
     */
    @Override
    public  void setStartTime(long startTime){this.startTime=startTime;};

    /**
     * 设置线程执行结束的时间，便于统计线程的执行效率和任务耗时量
     * @param endTime
     */
    @Override
    public  void setEndTime(long endTime){this.endTime=endTime;};

    @Override
    public String getTaskName() {
        return this.taskName;
    }

    @Override
    public int getTaskId() {
        return this.taskId;
    }



    @Override
    public long getStartTime() {
        return this.startTime;
    }

    @Override
    public long getExecuteTime() {
        return this.endTime-this.startTime;
    }

    @Override
    public long getEndTime() {
        return this.endTime;
    }


}
